<template>
    <div>
        <el-form :model="model" :rules="rules" ref="ruleForm" llabel-width="100px" class="demo-ruleForm">

            <el-form-item label="新增颜色" prop="Name">
                <el-input v-model="model.Name"></el-input>
            </el-form-item>

            <el-form-item>
                <el-button type="primary" @click="submitForm">{{ isUpdate ? '立即保存' : '提交' }}</el-button>
                <el-button @click="resetForm">重置</el-button>
            </el-form-item>
        </el-form>
    </div>
</template>

<script>
export default {
    props: {
        model: {
            require: true,
            type: Object
        },
        isUpdate: {
            require: true,
            type: Boolean
        }
    },
    data() {
        return {
            ColorList: [],
            rules: {
                Name: { required: true, message: "请输入盘号名称", trigg: 'blur' }
            }
        }
    },
    created() {
        this.getPanHaoAll();
    },
    methods: {
        submitForm() {
            this.$refs['ruleForm'].validate((valid) => {
                if (valid) {
                    if (this.isUpdate) {
                        this.put();
                    }
                    else {
                        this.add();
                    }
                } else {
                    this.showNotify('请输入必填项');
                    return false;
                }

            });
        },
        resetForm() {
            this.$refs['ruleForm'].resetFields()
        },
        add() {
            this.$http.postForm('/api/Color', { model: this.model }, { loading: this.$loading() })
                .then(res => {
                    this.$emit('callback');
                })
        },
        //修改
        put() {
            this.$http.putForm('/api/Color', { model: this.model }, { loading: this.$loading() })
                .then((res) => {
                    this.$emit('callback');
                })
        },

        getPanHaoAll() {
            this.$http.get('/api/Color/GetAll')
                .then(res => {
                    this.PanHaoList = res.Data;
                })
        }
    }
}
</script>

<style></style>